//
//  ZCTabBarController.m
//  DebugDemo
//
//  Created by XFB on 2018/11/8.
//  Copyright © 2018年 ZhouCheng. All rights reserved.
//

#import "ZCTabBarController.h"
#import "ZCNavigationController.h"

#import "BasicViewController.h"
#import "AdvanceViewController.h"


@interface ZCTabBarController ()

@end

@implementation ZCTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupBasicSet];
    
    [self addAllChildVc];
}

- (void)setupBasicSet
{
    self.tabBar.translucent = NO;
//    self.tabBar.tintColor = [UIColor orangeColor];
}

- (void)addAllChildVc
{
    BasicViewController *homeVc = [[NSBundle mainBundle] loadNibNamed:@"BasicViewController" owner:nil options:nil].lastObject;
    [self addOneChildVc:homeVc normalImageName:@"tabbar_home_normal" selectImageName:@"tabbar_home_select" title:@"基础"];
    
    AdvanceViewController *helpVc = [[AdvanceViewController alloc] init];
    [self addOneChildVc:helpVc normalImageName:@"tabbar_help_noraml" selectImageName:@"tabbar_help_select" title:@"进阶"];
}

- (void)addOneChildVc:(UIViewController *)childVc
      normalImageName:(NSString *)normalImageName
      selectImageName:(NSString *)selectImageName
                title:(NSString *)title
{
    childVc.title = title;
    childVc.tabBarItem.image = [UIImage imageNamed:normalImageName];
    childVc.tabBarItem.selectedImage = [UIImage imageNamed:selectImageName];
    
    // 设置tabBarItem的普通文字颜色
    UIColor * forgroundColor = UIColorFromRGB(0x8d8d8d);
    UIFont * forAttributeName = [UIFont systemFontOfSize:11];
    NSDictionary * textAttrsDict = @{
                                     NSForegroundColorAttributeName : forgroundColor,
                                     NSFontAttributeName            : forAttributeName
                                     };
    [childVc.tabBarItem setTitleTextAttributes:textAttrsDict forState:UIControlStateNormal];
    
    // 设置tabBarItem的选中文字颜色
    UIColor * selectedForgroundColor = UIColorFromRGB(0x288feb);
    UIFont * selectedForAttributeName = [UIFont systemFontOfSize:11];
    NSDictionary * selectedTextAttrsDict = @{
                                             NSForegroundColorAttributeName : selectedForgroundColor,
                                             NSFontAttributeName            : selectedForAttributeName
                                             };
    [childVc.tabBarItem setTitleTextAttributes:selectedTextAttrsDict forState:UIControlStateSelected];
    
    // 添加为tabbar控制器的子控制器
    ZCNavigationController * navi = [[ZCNavigationController alloc] initWithRootViewController:childVc];
    [self addChildViewController:navi];
}

@end
